import java.util.HashMap;
import java.util.Map;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/5
 * \* Time: 19:32
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 只出现一次的数字2 {
    public int singleNumber(int[] nums){
        Map<Integer, Integer> map=new HashMap<>();
        for(int i=0;i<nums.length;i++){
            int key=nums[i];
            //如果没出现则置为1，如果是多次出现value置为-1
            if(!map.containsKey(key)){
                map.put(key,1);
            }else {
                map.put(key,-1);
            }
        }

        for(Integer i:map.keySet()){
            if(map.get(i)==1){
                return i;
            }
        }
        return -1;
    }

}